package com.angel.webapp.servlets;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import com.angel.architecture.exceptions.NonBusinessException;
import com.angel.common.helpers.StringHelper;
import com.angel.configuration.JFigAdapterConfiguration;

/**
 * @author William
 * @since 13/August/2009
 */
public class InitializerServlet extends HttpServlet{

	private static final long serialVersionUID = 4401660661793903163L;
	
	private static final String IO_CONFIGURATION_FILE_NAME_KEY = "ioConfigFile";
	private static final String IO_CONFIGURATION_FILE_NAME = "io-config.xml";
	
	@Override
	public void init(ServletConfig servletConfig) {
        try {
			super.init(servletConfig);
			this.initializeConfiguration(servletConfig);
		} catch (ServletException e) {
			throw new NonBusinessException("Error initializing init servlet.", e);
		}
    }

	protected void initializeConfiguration(ServletConfig servletConfig) {
		String value = servletConfig.getInitParameter(IO_CONFIGURATION_FILE_NAME_KEY);
		if(StringHelper.isEmpty(value)){
			value = IO_CONFIGURATION_FILE_NAME;
		}
		JFigAdapterConfiguration.createInstance(value);
		
    }
}